{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Offline Training in Two Networks\n", "\n", "This notebook explores the EPIROB data in a two-step learning framework.\n", "\n", "**The single-step, feedforward inverse and forward model**\n", "\n", "This network takes sensor readings and the motor action made in that state, and outputs the next sensory state (a la \"prediction\"), and the *same* motor action. This model is designed to learn the effects of motor actions on the sensors, and to be able to take a hidden-layer representation and get the motor action back out (a motor decoder).\n", "\n", "
\n", "+---------------------+ +------------+\n", "| sensor_t1 | | motor_t0 |\n", "+---------------------+ +------------+\n", " ^ ^\n", " +---------------------+\n", " | hidden_t0 |\n", " +---------------------+\n", " ^ ^\n", "+---------------------+ +------------+\n", "| sensor_t0 | | motor_t0 |\n", "+---------------------+ +------------+\n", "\n", "\n", "\n", "**The hidden-space-only sequence network.**\n", "\n", "This network is also a feedforward network, learning to take hidden representations from the single-step network plus a hidden-layer representation of a goal, and give the next hidden layer representation. This network operates only in hidden space.\n", "\n", "
\n", " +---------------------+ \n", " | hidden_t1 | \n", " +---------------------+ \n", " ^\n", " +--------------+\n", " | hidden2 |\n", " +--------------+\n", " ^ ^\n", "+---------------------+ +---------------------+ \n", "| hidden_t0 | | hidden_goal | \n", "+---------------------+ +---------------------+ \n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Training" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import theano.tensor as T\n", "import numpy as np\n", "import sys\n", "sys.path.append(\"..\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using TensorFlow backend.\n" ] } ], "source": [ "from discover import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We import the discover program and load the experiment we are interested in:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "FLAGS.directory = \"../results\" # Where to save/restore files\n", "FLAGS.mode = 'test' # Should be 'wander' or 'test'\n", "FLAGS.num_steps = 5000 # Number of steps to wander and learn\n", "FLAGS.num_hiddens = 10 # Number of hidden units in model" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "____________________________________________________________________________________________________\n", "Layer (type) Output Shape Param # Connected to \n", "====================================================================================================\n", "g_in (InputLayer) (None, 10) 0 \n", "____________________________________________________________________________________________________\n", "s_in (InputLayer) (None, 19) 0 \n", "____________________________________________________________________________________________________\n", "m_in (InputLayer) (None, 2) 0 \n", "____________________________________________________________________________________________________\n", "c_in (InputLayer) (None, 10) 0 \n", "____________________________________________________________________________________________________\n", "merge_1 (Merge) (None, 41) 0 \n", "____________________________________________________________________________________________________\n", "h (Dense) (None, 10) 420 \n", "____________________________________________________________________________________________________\n", "g_out (Dense) (None, 10) 110 \n", "____________________________________________________________________________________________________\n", "s_out (Dense) (None, 19) 209 \n", "____________________________________________________________________________________________________\n", "m_out (Dense) (None, 2) 22 \n", "====================================================================================================\n", "Total params: 761.0\n", "Trainable params: 761.0\n", "Non-trainable params: 0.0\n", "____________________________________________________________________________________________________\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "../discover.py:78: UserWarning: The `merge` function is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc.\n", " x = merge([g_in, s_in, m_in, c_in], mode='concat')\n", "/usr/local/lib/python3.5/dist-packages/keras/legacy/layers.py:456: UserWarning: The `Merge` layer is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc.\n", " name=name)\n", "../discover.py:83: UserWarning: Update your `Model` call to the Keras 2 API: `Model(outputs=[